import playerDataInfo from "./playerData";

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
    @property(cc.Label)
    txtCoin: cc.Label = null;
    @property(cc.Label)
    txtTiLi: cc.Label = null;
    @property(cc.Label)
    txtAttackNum: cc.Label = null;
    @property(cc.Label)
    txtLevelCoin: cc.Label = null;
    @property(cc.Node)
    nodePlayer: cc.Node = null;
    onLoad() {
        console.log("⣿⣿⣿⣿⣿⠟⠋⠄⠄⠄⠄⠄⠄⠄⢁⠈⢻⢿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⠃⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⡀⠭⢿⣿⣿⣿⣿\n⣿⣿⣿⣿⡟⠄⢀⣾⣿⣿⣿⣷⣶⣿⣷⣶⣶⡆⠄⠄⠄⣿⣿⣿⣿\n⣿⣿⣿⣿⡇⢀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠄⠄⢸⣿⣿⣿⣿\n⣿⣿⣿⣿⣇⣼⣿⣿⠿⠶⠙⣿⡟⠡⣴⣿⣽⣿⣧⠄⢸⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣾⣿⣿⣟⣭⣾⣿⣷⣶⣶⣴⣶⣿⣿⢄⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⡟⣩⣿⣿⣿⡏⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣹⡋⠘⠷⣦⣀⣠⡶⠁⠈⠁⠄⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣍⠃⣴⣶⡔⠒⠄⣠⢀⠄⠄⠄⡨⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣦⡘⠿⣷⣿⠿⠟⠃⠄⠄⣠⡇⠈⠻⣿⣿⣿⣿\n⣿⣿⣿⣿⡿⠟⠋⢁⣷⣠⠄⠄⠄⠄⣀⣠⣾⡟⠄⠄⠄⠄⠉⠙⠻\n⡿⠟⠋⠁⠄⠄⠄⢸⣿⣿⡯⢓⣴⣾⣿⣿⡟⠄⠄⠄⠄⠄⠄⠄⠄\n⠄⠄⠄⠄⠄⠄⠄⣿⡟⣷⠄⠹⣿⣿⣿⡿⠁⠄⠄⠄⠄⠄⠄⠄⠄\n")
        playerDataInfo.initData();
        this.initData();
    }

    initData() {
        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStartCallback, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEndCallback, this);
        //@ts-ignore
        this.txtCoin.string = playerDataInfo.gameData.coin;
        //@ts-ignore
        this.txtTiLi.string = playerDataInfo.gameData.tiLi;
        //@ts-ignore
        this.txtAttackNum.string = playerDataInfo.gameData.playerLevel;
        //@ts-ignore
        this.txtLevelCoin.string = playerDataInfo.gameData.playerLevel * 10;
        cc.director.preloadScene("gameMain");

    }

    onBtnSettingCallbacl() {

    }

    private startPosi;
    onTouchStartCallback(event) {
        this.startPosi = event.getLocation();
    }

    onTouchEndCallback(event) {
        let end_y = event.getLocation().y;
        let diff = end_y - this.startPosi.y;
        if (diff >= 400) {
            //@ts-ignore
            if (playerDataInfo.gameData.tiLi > 0) {
                //进入游戏
                cc.tween(this.nodePlayer)
                    .to(0.8, { position: cc.v3(this.nodePlayer.x, this.nodePlayer.y + 1200) })
                    .call(() => {
                        cc.director.loadScene("gameMain");
                    })
                    .start()
            }
            else {
                //获得体力
                console.log("体力不足")
            }
        }
    }

    onButtomShenJiAttackCallback() {
        //@ts-ignore
        if (Number(playerDataInfo.gameData.coin) >= Number(this.txtLevelCoin.string)) {
            //@ts-ignore
            playerDataInfo.setGameDataByKey("playerLevel", Number(playerDataInfo.gameData.playerLevel) + 1);
            //@ts-ignore
            let coin = playerDataInfo.gameData.coin - Number(this.txtLevelCoin.string);
            this.txtCoin.string = String(coin);
            playerDataInfo.setGameDataByKey("coin", coin);
            //@ts-ignore
            this.txtAttackNum.string = Number(playerDataInfo.gameData.playerLevel);
            this.txtLevelCoin.string = String(Number(this.txtAttackNum.string) * 10);
        }
        else {
            console.log("金币不足")
        }
    }
}
